package com.jemframework.utils;

import com.jemframework.utils.stringformatter.StringFormat;
import com.jemframework.utils.stringformatter.StringFormatter;
import com.jemframework.utils.stringformatter.StringFormatterFactory;

public class StringUtils {

  public static String capitalize(String string) {
    StringBuffer buff = new StringBuffer();
    Character ch = Character.valueOf(string.charAt(0));
    ch = Character.toUpperCase(ch);
    buff.append(ch).append(string.substring(1));
    return buff.toString();
  }

  public static String formatString(String aString, StringFormat anInputFormat, StringFormat anOutputFormat) {

    if (anInputFormat == anOutputFormat) {
      // OPTIMIZATION: formatting is not really needed.
      return aString;
    }

    StringFormatter theFormatter = StringFormatterFactory.getInstance().getStringFormatter(anOutputFormat);
    String theFormattedString = theFormatter.formatString(anInputFormat, aString);
    return theFormattedString;
  }
}
